<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		content="initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no,uc-fitscreen=yes">
	<title>{$info.company_name|default=''}</title>
	<link rel="stylesheet" href="/public/static/mobile/css/base.css" />
	<link rel="stylesheet" href="/public/static/mobile/css/popup.css" />
	<link rel="stylesheet" href="/public/static/mobile/css/footer.css" />
	<script src="/public/static/mobile/js/vue.js"></script>
	<script src="/public/static/mobile/js/vue-resource.min.js"></script>
	<script type="text/javascript" src="/public/static/mobile/js/page.js"></script>
	<script src="/public/static/mobile/js/axios.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
	<script src="/public/static/js/jsQR.js"></script>
	<style type="text/css">
        .scan {
 height: 100%;
        }
 #bcid {
  width: 100%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom:3rem;
  text-align: center;
  color: #fff;
  background: #ccc;
 }
 footer {
  position: absolute;
  left: 0;
  bottom: 1rem;
  height: 2rem;
  line-height: 2rem;
  z-index: 2;
 }
 
    </style>
</head>

<body>
	<div id="index">
		<button @click.native='startRecognize'>触发按钮</button>
<div id="bcid" :style='{zIndex:zIndex}'></div>   

    <div @click="fanhui">返回</div>

	</div>
</body>

<script type="text/javascript">
let scan = null;
	new Vue({
		el: '#index',
		data: function () {
			return {
				text:'',
            codeUrl: '',
            scan:'',
            zIndex:-1,
            sn:"",
			}
		},
    // 创建页面
		created(){
			var _this=this;
			// 获取上一页面的参数
			var sn = decodeURI(window.location.href.split("?")[1]);
			_this.sn=sn.slice(3);
      console.log(_this.sn)
			
		},
		//页面加载需要执行的方法
		mounted: function () {
			var _this = this;
			
		},
		methods: {
      
      fanhui(){
        // window.history.go(-1); 
				// location.replace('/mobile/index/index.html')
        window.location.href="/mobile/index/index.html?sn="+this.sn+"&type=2";
        window.close();

        // window.open('/mobile/index/index.html');    //跳转
        // window.history.back(-1);    //返回上一页面
      },
			//初始化扫描控件
            startRecognize() { 
        this.zIndex=9999
        let that = this;
        if (!window.plus) {return};
        // 初始化扫描控件
        this.scan = new plus.barcode.Barcode('bcid');
        this.scan.onmarked = onmarked; 
        // 调用开始扫描 
        this.startScan()
        // 扫描后回调
        function onmarked(type, result, file) { 
          switch (type) {
            case plus.barcode.QR:
              type = 'QR';
              break;
            case plus.barcode.EAN13:
              type = 'EAN13';
              break;
            case plus.barcode.EAN8:
              type = 'EAN8';
              break;
            default:
              type = '其它' + type;
              break;
          }
          result = result.replace(/\n/g, '');
          that.codeUrl = result;
          // 返回值
          //Toast(result);  
          that.zIndex=-1
          that.closeScan(); 
        }
      },
      //开始扫描
      startScan() { 
        if (!window.plus) return;
        this.scan.start();
      },
      //关闭扫描
      cancelScan() { 
        if (!window.plus) return;
        that.zIndex=-1
        this.scan.cancel();
      },
      //关闭条码识别控件
      closeScan() { 
        if (!window.plus) return;
        this.scan.close();
      }, 

		}
	})
</script>


</html>